from selenium import webdriver
from time import sleep
from selenium.webdriver.common.by import By
from selenium.webdriver.support.ui import WebDriverWait

driver = webdriver.Chrome()           #获取对象
driver.implicitly_wait(10)  # 隐式等待
driver.get("http://localhost:8080/woniusales")   #打开蜗牛进销存
driver.maximize_window()
# 登录
def test_login():
    try:
        driver.find_element_by_id('username').send_keys('admin')
        driver.find_element_by_id('password').send_keys('admin123')
        driver.find_element_by_id('verifycode').send_keys('0000')
        driver.find_element_by_xpath('/html/body/div[4]/div/form/div[6]/button').click()
    except:
        print('检查错误')

# 商品出库
def test_sell():
    driver.find_element_by_xpath('//*[@id="barcode"]').send_keys('6955203662897')
    driver.find_element_by_xpath('/html/body/div[4]/div[1]/div/div[1]/form/button').click()
    # driver.find_element_by_xpath('//*[@id="paymethod"]').click()
    driver.find_element_by_xpath('/html/body/div[4]/div[4]/div[1]/form/div[1]/select/option[4]').click()
    driver.find_element_by_id('submit').click()
    driver.switch_to.alert.accept()
    driver.switch_to.alert.dismiss()
    # driver.quit()

# 批次管理
def test_goods():
    driver.find_element_by_xpath('//*[@id="navbar"]/ul[1]/li[2]/a').click()
    driver.find_element_by_xpath('//*[@id="batchnamelist"]/option[5]').click()
    driver.find_element_by_xpath('/html/body/div[4]/div[1]/form[2]/div/input[2]').click()

# 商品入库
def test_store():
    WebDriverWait(driver=driver,timeout=10).until(lambda x:x.find_element_by_xpath('//*[@id="navbar"]/ul[1]/li[3]/a'))
    driver.find_element_by_xpath('//*[@id="navbar"]/ul[1]/li[3]/a').click()
    driver.find_element_by_xpath('//*[@id="batchname"]/option[6]').click()
    driver.find_element_by_id('goodsserial').send_keys('MT777777')
    driver.find_element_by_id('barcode').send_keys('MT777777')
    driver.find_element_by_xpath('//*[@id="inputsize"]').send_keys('s-m-l')
    driver.find_element_by_xpath('//*[@id="quantity"]').send_keys('30')
    driver.find_element_by_xpath('/html/body/div[4]/div[1]/form[2]/div/input').click()
    driver.switch_to.alert.accept()

# 库存查询
def test_query():
    WebDriverWait(driver=driver,timeout=10).until(lambda x:x.find_element_by_xpath('//*[@id="navbar"]/ul[1]/li[4]/a'))
    driver.find_element_by_xpath('//*[@id="navbar"]/ul[1]/li[4]/a').click()  # 跳转到库存查询
    driver.find_element_by_xpath('//*[@id="goodsserial"]').send_keys('M4S4227C')  # 输入货号
    driver.find_element_by_xpath('//*[@id="goodsname"]').send_keys('针织打底')  # 输入品名
    driver.find_element_by_xpath('//*[@id="barcode"]').send_keys('6955203656858')  # 条码
    driver.find_element_by_xpath('//*[@id="goodstype"]/option[2]').click()  # 类别
    driver.find_element_by_xpath('/html/body/div[4]/div[1]/form[2]/div[2]/input[1]').click()
    sleep(1)
    driver.find_element_by_xpath('/html/body/div[4]/div[1]/form[2]/div[2]/input[2]').click()
    sleep(1)
    driver.find_element_by_xpath('/html/body/div[4]/div[1]/form[2]/div[2]/input[3]').click()

# 会员管理
def test_customer():
    WebDriverWait(driver=driver,timeout=10).until(lambda x:x.find_element_by_xpath('//*[@id="navbar"]/ul[1]/li[5]/a'))
    driver.find_element_by_xpath('//*[@id="navbar"]/ul[1]/li[5]/a').click()
    driver.find_element_by_xpath('//*[@id="customerphone"]').send_keys('15755667788')
    name=driver.find_element_by_xpath('//*[@id="customername"]')
    name.clear()
    name.send_keys('feiy')
    driver.find_element_by_xpath('/html/body/div[4]/div[1]/form[2]/div[2]/button[1]').click()
    driver.find_element_by_xpath('/html/body/div[7]/div/div/div[3]/button').click()

# 销售报表
def test_report():
    WebDriverWait(driver=driver,timeout=10).until(lambda x:x.find_element_by_xpath('//*[@id="navbar"]/ul[1]/li[6]/a'))
    driver.find_element_by_xpath('//*[@id="navbar"]/ul[1]/li[6]/a').click()
    driver.find_element_by_xpath('/html/body/div[4]/div[2]/form/div/button[1]').click()
    driver.find_element_by_xpath('/html/body/div[4]/div[2]/form/div/button[2]').click()
    driver.find_element_by_xpath('/html/body/div[4]/div[2]/form/div/button[3]').click()
    driver.find_element_by_xpath('/html/body/div[4]/div[2]/form/div/button[4]').click()
    driver.find_element_by_xpath('/html/body/div[4]/div[2]/form/div/button[5]').click()
    driver.find_element_by_xpath('/html/body/div[4]/div[2]/form/div/button[6]').click()
    driver.find_element_by_xpath('/html/body/div[4]/div[2]/form/div/button[7]').click()
    driver.find_element_by_xpath('/html/body/div[4]/div[2]/form/div/button[8]').click()
    driver.find_element_by_xpath('/html/body/div[4]/div[2]/form/div/button[9]').click()


if __name__ == '__main__':
    test_login()
    test_query()
    test_customer()
    test_report()








